<!DOCTYPE html>
<html>
<head>
<#include "/freemarker/fw/meta_top.ftl">
    <title>${chapter.book.bookname} | ${chapter.title}</title>
<#include "/freemarker/fw/load_static.ftl">
    <script src="/asset/ueditor/ueditor.config.js"></script>
    <script src="http://ueditor.baidu.com/ueditor/ueditor.all.js"></script>
</head>
<body>
<#include "/freemarker/fw/navbar_top.ftl">
<div class="container">
<#--<form method="post" action="/book/create">-->
    <p>
        <input class="center-block btn-block" name="title" value="${chapter.title}" placeholder="章节标题">
    </p>

    <div>
        <script type="text/plain" id="editor">${chapter.text}</script>
    </div>
    <p>
        <button style="margin: 10px 0;"  class="btn btn-default btn-block" type="submit">提交</button>
    </p>
<#--</form>-->
    <script>
        $(document).ready(function () {
            var editor = new UE.getEditor("editor");
            $("button[type='submit']").on("click", function(){
                var jqxhr = $.post("/chapter/edit/${chapter.id}",{
                    title: $("input[name='title']").val(),
                    text: editor.getContent()
                });
                jqxhr.done(function(response){
                    window.location.href = "/chapter/${chapter.id}";
                });
            })
        })
    </script>
</div>
</body>
</html>